﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;

namespace WebFrontEnd
{
    /// <summary>
    /// Summary description for QRGenerator
    /// </summary>
    public class QRGenerator : IHttpHandler
    {
        IQREncoder encoder = new MessagingToolkitQREncoder();
        public void ProcessRequest(HttpContext context)
        {
            string inviteID = context.Request.QueryString["iid"];
            BusinessEntities.Model.Invite invite = BusinessLayer.BusinessLayerFactory.GetCurrentBusinessLayer(ConfigurationManager.AppSettings.Get("DomainName")).GetInviteById(int.Parse(inviteID));
            var bmp = encoder.GetQRBitmap(string.Format("http://{0}/RSVP.aspx?gid={1}&h={2}",ConfigurationManager.AppSettings.Get("DomainName"),invite.GuestID,invite.Hash));
            context.Response.ContentType = "image/gif";
            bmp.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Gif);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}